

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" href="/img/favicon.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Fly542">
  <meta name="keywords" content="">
  
    <meta name="description" content="常规操作1. 远程主机操作&#x2F;&#x2F; 查看该主机的详细信息 $ git remote show &lt;主机名&gt; &#x2F;&#x2F; 添加远程主机，添加后通过《 8.取回远程主机某个分支的更新》来建立本地新的分支 $ git remote add &lt;主机名&gt; &lt;网址&gt; &#x2F;&#x2F; 删除远程主机 $ git remote rm &lt;主机名&gt; 远程主机的改名 $ git remote r">
<meta property="og:type" content="article">
<meta property="og:title" content="常用git命令">
<meta property="og:url" content="http://fly542.cn/2020/07/27/04DevOps/00%E5%B8%B8%E7%94%A8git%E5%91%BD%E4%BB%A4/index.html">
<meta property="og:site_name" content="Fly542 技术沉淀">
<meta property="og:description" content="常规操作1. 远程主机操作&#x2F;&#x2F; 查看该主机的详细信息 $ git remote show &lt;主机名&gt; &#x2F;&#x2F; 添加远程主机，添加后通过《 8.取回远程主机某个分支的更新》来建立本地新的分支 $ git remote add &lt;主机名&gt; &lt;网址&gt; &#x2F;&#x2F; 删除远程主机 $ git remote rm &lt;主机名&gt; 远程主机的改名 $ git remote r">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-07-27T09:39:42.000Z">
<meta property="article:modified_time" content="2023-04-25T09:41:14.000Z">
<meta property="article:author" content="Fly542">
<meta property="article:tag" content="git">
<meta name="twitter:card" content="summary_large_image">
  
  
  <title>常用git命令 - Fly542 技术沉淀</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css" />
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hint.css@2/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css" />
  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"fly542.cn","root":"/","version":"1.8.14","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 6.0.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>Fly542 技术沉淀</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="常用git命令">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2020-07-27 17:39" pubdate>
        2020年7月27日 下午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      4.9k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      42 分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">常用git命令</h1>
            
            <div class="markdown-body">
              <h2 id="常规操作"><a href="#常规操作" class="headerlink" title="常规操作"></a>常规操作</h2><h3 id="1-远程主机操作"><a href="#1-远程主机操作" class="headerlink" title="1. 远程主机操作"></a>1. 远程主机操作</h3><div class="code-wrapper"><pre><code class="hljs">// 查看该主机的详细信息
$ git remote show &lt;主机名&gt;
// 添加远程主机，添加后通过《 8.取回远程主机某个分支的更新》来建立本地新的分支
$ git remote add &lt;主机名&gt; &lt;网址&gt;
// 删除远程主机
$ git remote rm &lt;主机名&gt;
远程主机的改名
$ git remote rename &lt;原主机名&gt; &lt;新主机名&gt;
</code></pre></div>
<h3 id="2-checkout-远端指定分支"><a href="#2-checkout-远端指定分支" class="headerlink" title="2.checkout 远端指定分支"></a>2.checkout 远端指定分支</h3><div class="code-wrapper"><pre><code class="hljs">$ git checkout -b xxxx&lt;本地分支名称&gt; yyyy&lt;远端分支名&gt;
</code></pre></div>
<h3 id="3-合并多个commit"><a href="#3-合并多个commit" class="headerlink" title="3.合并多个commit"></a>3.合并多个commit</h3><div class="code-wrapper"><pre><code class="hljs">$ git rebase -i HEAD~n  
// 将commit的前n个合并，在出现的窗口中将要合并的pick修改为squash
$ git push -f
</code></pre></div>
<h3 id="4-清理远端已经删除的本地分支"><a href="#4-清理远端已经删除的本地分支" class="headerlink" title="4.清理远端已经删除的本地分支"></a>4.清理远端已经删除的本地分支</h3><div class="code-wrapper"><pre><code class="hljs">$ git pull -p
// 等同于下面的命令
$ git fetch --prune origin 
$ git fetch -p
</code></pre></div>
<h3 id="5-删除远端分支"><a href="#5-删除远端分支" class="headerlink" title="5.删除远端分支"></a>5.删除远端分支</h3><div class="code-wrapper"><pre><code class="hljs">$ git push origin :xxx
// 等同于
$ git push origin --delete xxx
</code></pre></div>
<h3 id="6-清理本地没有的tag"><a href="#6-清理本地没有的tag" class="headerlink" title="6.清理本地没有的tag"></a>6.清理本地没有的tag</h3><div class="code-wrapper"><pre><code class="hljs">// 先清理本地所有tag再获取远端的tag
$ git tag -l | xargs git tag -d
$ git fetch -t -p -f
</code></pre></div>
<h3 id="7-推送到远端"><a href="#7-推送到远端" class="headerlink" title="7.推送到远端"></a>7.推送到远端</h3><div class="code-wrapper"><pre><code class="hljs">$ git push &lt;远程主机名&gt; &lt;本地分支名&gt;:&lt;远程分支名&gt;
// 将本地分支推送到远端特定分支时出错先使用merge命令将远程分支合并到本地并解决冲突后提交, 然后再使用push命令
$ git merge &lt;远程主机名&gt;/&lt;远程分支名&gt;
</code></pre></div>
<h3 id="8-取回远程主机某个分支的更新"><a href="#8-取回远程主机某个分支的更新" class="headerlink" title="8.取回远程主机某个分支的更新"></a>8.取回远程主机某个分支的更新</h3><div class="code-wrapper"><pre><code class="hljs">git pull &lt;远程主机名&gt; &lt;远程分支名&gt;:&lt;本地分支名&gt;
</code></pre></div>
<h3 id="9-撤销commit，但未git-push的命令"><a href="#9-撤销commit，但未git-push的命令" class="headerlink" title="9.撤销commit，但未git push的命令"></a>9.撤销commit，但未git push的命令</h3><div class="code-wrapper"><pre><code class="hljs">// 完成撤销,同时将代码恢复到前一commit_id 对应的版本
$ git reset --hard id 
// 完成Commit命令的撤销，但是不对代码修改进行撤销，可以直接通过git commit 重新提交对本地代码的修改
$ git reset id 
// 撤销当前的所有修改
$ git reset --hard HEAD
</code></pre></div>
<h3 id="10-master-回退服务端到特定版本"><a href="#10-master-回退服务端到特定版本" class="headerlink" title="10. master 回退服务端到特定版本"></a>10. master 回退服务端到特定版本</h3><div class="code-wrapper"><pre><code class="hljs">// checkout 要回退的当前最新版(如源名是upstream)
$ git checkout -b upstream_master upstream/master
// 回退到2295c189c22b960e2852f5b0495c7173b404b270 
$ git reset --hard 2295c189c22b960e2852f5b0495c7173b404b270
// 强制推送当前版本到主干
$ git push upstream HEAD:master
</code></pre></div>
<h3 id="11-比较两个版本间的差异"><a href="#11-比较两个版本间的差异" class="headerlink" title="11.比较两个版本间的差异"></a>11.比较两个版本间的差异</h3><div class="code-wrapper"><pre><code class="hljs">$ git diff commit_id_old commit_id_new
</code></pre></div>
<h3 id="12-更改远端分支"><a href="#12-更改远端分支" class="headerlink" title="12.更改远端分支"></a>12.更改远端分支</h3><div class="code-wrapper"><pre><code class="hljs">// 先删除老的分支
$ git push --delete origin old_branch
// 修改本地的分支名
$ git branch -m old_branch new_branch
// 推送本地的新分支到远端
$ git push origin new_branch:new_branch
</code></pre></div>
<h3 id="13-生成patch"><a href="#13-生成patch" class="headerlink" title="13.生成patch"></a>13.生成patch</h3><div class="code-wrapper"><pre><code class="hljs">// 生成从commitid为xxx到当前提交的patch，每个提交一个patch文件, 存放在当前的dir目录下
$ git format-patch xxx -o dir
</code></pre></div>
<h3 id="14-应用patch"><a href="#14-应用patch" class="headerlink" title="14.应用patch"></a>14.应用patch</h3><div class="code-wrapper"><pre><code class="hljs">// 先检测xxx.patch文件是否和当前的版本有冲突
$ git apply --check xxx.patch
// 再将xxx.patch合并到当前的分支中
$ git apply xxx.patch
</code></pre></div>
<h3 id="15-修改源地址"><a href="#15-修改源地址" class="headerlink" title="15.修改源地址"></a>15.修改源地址</h3><div class="code-wrapper"><pre><code class="hljs">$ git remove set-url origin newaddr
</code></pre></div>
<h3 id="16-合并某个commit到当前aa分支上"><a href="#16-合并某个commit到当前aa分支上" class="headerlink" title="16.合并某个commit到当前aa分支上"></a>16.合并某个commit到当前aa分支上</h3><div class="code-wrapper"><pre><code class="hljs">// 其中commit_id是某个非aa分支上的commit_id
$ git checkout aa
$ git cherry-pick commit_id
</code></pre></div>
<h3 id="17-修改分支名"><a href="#17-修改分支名" class="headerlink" title="17. 修改分支名"></a>17. 修改分支名</h3><div class="code-wrapper"><pre><code class="hljs">$ git  branch -m old_branch new_branch
</code></pre></div>
<h3 id="18-合并分支多个commit到主分支，使主分支只有有一个干净清晰的log"><a href="#18-合并分支多个commit到主分支，使主分支只有有一个干净清晰的log" class="headerlink" title="18. 合并分支多个commit到主分支，使主分支只有有一个干净清晰的log"></a>18. 合并分支多个commit到主分支，使主分支只有有一个干净清晰的log</h3><div class="code-wrapper"><pre><code class="hljs">$ git checkout master //切换回主分支
$ git pull origin master //拉取远端master代码
$ git merge --squash 分支名  //如遇冲突就解决冲突
$ git commit -m &quot;这里是注释&quot;
$ git push origin master //提交master代码到远端
</code></pre></div>
<h3 id="19-git-submodule-添加子仓库"><a href="#19-git-submodule-添加子仓库" class="headerlink" title="19.git submodule 添加子仓库"></a>19.git submodule 添加子仓库</h3><p>Git Submodule 允许一个git仓库，作为另一个git仓库的子目录，并且保持父项目和子项目相互独立</p>
<div class="code-wrapper"><pre><code class="hljs">// 查看子模块
git submodule
// 为当前工程添加指定分支 xx 的 submodule
git submodule add -b xx &lt;仓库地址&gt; &lt;本地路径&gt;
// 为当前工程添加submodule
git submodule add &lt;仓库地址&gt; &lt;本地路径&gt;
// 下载的工程带有submodule,使用以下命令下载子模块内容
git submodule update --init --recursive
// 更新子模块为远程项目的最新版本
git submodule update --remote
// 删除子模块需要经过以下4步, 以删除assets文件夹为例
    // 1. 删除子模块文件夹
    git rm --cached assets
    // 2. 删除.gitmodules文件中相关子模块信息
    // 3. 删除.git/config中的相关子模块信息
    // 4. 删除.git/modules/src/文件夹中的相关子模块文件
</code></pre></div>
<h3 id="20-更新源地址"><a href="#20-更新源地址" class="headerlink" title="20 更新源地址"></a>20 更新源地址</h3><div class="code-wrapper"><pre><code class="hljs">$ git remote set-url origin &lt;new_addr&gt;
</code></pre></div>
<h3 id="21-创建空白分支"><a href="#21-创建空白分支" class="headerlink" title="21 创建空白分支"></a>21 创建空白分支</h3><div class="code-wrapper"><pre><code class="hljs">利用git checkout的 --orphan参数来建立一个没有任何历史记录的空分支
// 1. 建立命令为空分支
git checkout --orphan test_empty
// 2. 删除所有文件, 注意后面的.
git rm -rf .
// 3. 添加新的文件, 未添加新的文件则分支 test_empty 不可见
git add xxx
git ci -a &quot;add xxx file&quot;
// 4. 推送到远端
git push --set-upstream origin test_empty
</code></pre></div>
<h3 id="22-查看当前配置信息"><a href="#22-查看当前配置信息" class="headerlink" title="22 查看当前配置信息"></a>22 查看当前配置信息</h3><div class="code-wrapper"><pre><code class="hljs">// 查看全局配置信息
git config --system --list
// 查看当前用户的global全局配置
git config --global --list
// 查看当前仓库配置信息
git config --local --list
</code></pre></div>
<h2 id="二-tag-操作"><a href="#二-tag-操作" class="headerlink" title="二. tag 操作"></a>二. tag 操作</h2><h3 id="1-显示本地-tag"><a href="#1-显示本地-tag" class="headerlink" title="1. 显示本地 tag"></a>1. 显示本地 tag</h3><div class="code-wrapper"><pre><code class="hljs">git tag
</code></pre></div>
<h3 id="2-删除本地tag"><a href="#2-删除本地tag" class="headerlink" title="2. 删除本地tag"></a>2. 删除本地tag</h3><div class="code-wrapper"><pre><code class="hljs">// 删除名为tag_name的一个标签
git tag -d tag_name
// 删除本地所有标签
git tag -d $(git tag -l)
</code></pre></div>
<h3 id="3-删除远端某个tag"><a href="#3-删除远端某个tag" class="headerlink" title="3. 删除远端某个tag"></a>3. 删除远端某个tag</h3><div class="code-wrapper"><pre><code class="hljs">// 删除远端名为release-3.0.0-13的tag
git push origin :refs/tags/release-3.0.0-13
// 删除远端所有的标签
git push origin --delete $(git tag -l)
</code></pre></div>
<h3 id="4-批量删除远端tag"><a href="#4-批量删除远端tag" class="headerlink" title="4.批量删除远端tag"></a>4.批量删除远端tag</h3><div class="code-wrapper"><pre><code class="hljs">//删除远端所有以release-开头的tag
git show-ref --tag | awk &#39;/release-/ &#123;print &quot;:&quot; $2&#125;&#39; |xargs git push origin
</code></pre></div>
<h3 id="5-批量删除本地分支"><a href="#5-批量删除本地分支" class="headerlink" title="5. 批量删除本地分支"></a>5. 批量删除本地分支</h3><div class="code-wrapper"><pre><code class="hljs">// 删除以release-开头的本地tag
git tag -l | awk &#39;/release-/&#39; |  xargs git tag -d
</code></pre></div>
<h3 id="6-添加标签"><a href="#6-添加标签" class="headerlink" title="6.添加标签"></a>6.添加标签</h3><div class="code-wrapper"><pre><code class="hljs">// 添加一个名为xxx的标签
$git tag -a xxx -m&quot;xxxxxxx&quot;
// 将标签推送到服务器
$git push origin tag-names
</code></pre></div>
<h2 id="三-遇到问题及解决方法"><a href="#三-遇到问题及解决方法" class="headerlink" title="三. 遇到问题及解决方法"></a>三. 遇到问题及解决方法</h2><h3 id="1-git-push-或者-clone-出错"><a href="#1-git-push-或者-clone-出错" class="headerlink" title="1. git push 或者 clone 出错"></a>1. git push 或者 clone 出错</h3><p>出错代码:<br>    <figure class="highlight subunit"><table><tr><td class="gutter"><div class="code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></div></td><td class="code"><pre><code class="hljs subunit"><span class="hljs-keyword">error: </span>RPC failed; curl 56 OpenSSL SSL_read: error:1408F119:SSL routines:ssl3_get_record:decryption failed or bad record mac, errno 0<br>fatal: the remote end hung up unexpectedly<br>fatal: early EOF<br>fatal: index-pack failed<br></code></pre></td></tr></table></figure></p>
<p>解决方法：增大 postbuffer<br>    <figure class="highlight lua"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs lua">git <span class="hljs-built_in">config</span> <span class="hljs-comment">--global http.postBuffer 1048576000</span><br></code></pre></td></tr></table></figure></p>
<h3 id="2-git-archive-时没有同步submodule"><a href="#2-git-archive-时没有同步submodule" class="headerlink" title="2. git archive 时没有同步submodule"></a>2. git archive 时没有同步submodule</h3><p>在使用 git archive的时候，发现并没有把项目里的submodule里的文件归档过去，只有一个submodule的文件夹</p>
<p>解决思路：1、先在父目录使用git archive后，再通过git submodule foreach遍历submodule，对sudmodule里的文件进行git archive，这样最后，所有文件都能归档到一个地方了</p>
<div class="code-wrapper"><pre><code class="hljs"><figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></div></td><td class="code"><pre><code class="hljs routeros"><span class="hljs-comment"># 函数第一个参数为项目名</span><br>function pack() &#123;<br>	<span class="hljs-attribute">PKG_NAME</span>=<span class="hljs-variable">$&#123;1&#125;</span><br>	<span class="hljs-attribute">PKG_VERSION</span>=$(grep <span class="hljs-string">&#x27;^Version:&#x27;</span> <span class="hljs-variable">$&#123;PKG_NAME&#125;</span>.spec | awk <span class="hljs-string">&#x27;&#123;print $2&#125;&#x27;</span>)<br>	cd <span class="hljs-built_in">..</span><br>	<span class="hljs-attribute">curDir</span>=`pwd`<br>	<span class="hljs-attribute">PROJECT_NAME</span>=<span class="hljs-string">&quot;<span class="hljs-variable">$&#123;PKG_NAME&#125;</span>-<span class="hljs-variable">$&#123;PKG_VERSION&#125;</span>&quot;</span><br>	git archive <span class="hljs-attribute">--format</span>=tar <span class="hljs-attribute">--prefix</span>=<span class="hljs-variable">$PROJECT_NAME</span>/ HEAD | (tar xpf -) #归档父项目后解压到指定目录<br>	git submodule <span class="hljs-keyword">foreach</span> | <span class="hljs-keyword">while</span> read subdir; <span class="hljs-keyword">do</span> <br>		<span class="hljs-attribute">subdir</span>=<span class="hljs-variable">$&#123;subdir#*\&#x27;&#125;</span>; #去除最左边的单引号<br>		<span class="hljs-attribute">subdir</span>=<span class="hljs-variable">$&#123;subdir%*\&#x27;&#125;</span>; #去除最右边的单引号<br>		[ <span class="hljs-string">&quot;<span class="hljs-variable">$&#123;subdir&#125;</span>&quot;</span> = <span class="hljs-string">&quot;&quot;</span> ] &amp;&amp; continue; #加一步判断，subdir为<span class="hljs-string">&quot;&quot;</span>则continue<br>		echo Running git archive submodules<span class="hljs-built_in">..</span>. <span class="hljs-variable">$&#123;subdir&#125;</span><br>		(cd <span class="hljs-variable">$&#123;subdir&#125;</span> &amp;&amp; git archive <span class="hljs-attribute">--format</span>=tar <span class="hljs-attribute">--prefix</span>=<span class="hljs-variable">$&#123;subdir&#125;</span>/ HEAD | (cd <span class="hljs-variable">$&#123;curDir&#125;</span>/<span class="hljs-variable">$&#123;PROJECT_NAME&#125;</span>/ &amp;&amp; tar xpf -)); #归档submodule后解压到父目录<br>	done<br><br>	tar zcpf <span class="hljs-variable">$&#123;PROJECT_NAME&#125;</span>.tar.gz <span class="hljs-variable">$&#123;PROJECT_NAME&#125;</span><br>	/bin/mv -f <span class="hljs-variable">$&#123;PROJECT_NAME&#125;</span>.tar.gz packaging<br>	rm -rf <span class="hljs-variable">$&#123;PKG_NAME&#125;</span>-<span class="hljs-variable">$&#123;PKG_VERSION&#125;</span><br>	cd -<br>&#125;<br></code></pre></td></tr></table></figure>
</code></pre>
<h3 id="3-git-status-中文显示乱码"><a href="#3-git-status-中文显示乱码" class="headerlink" title="3. git status 中文显示乱码"></a>3. git status 中文显示乱码</h3><p><strong>原因:</strong></p>
<p>在默认设置下，中文文件名在工作区状态输出，中文名不能正确显示，而是显示为八进制的字符编码。</p>
<p><strong>解决办法:</strong></p>
<p>将git配置文件 core.quotepath项设置为false。quotepath表示引用路径，加上–global表示全局配置</p>
<p>git bash终端输入命令:</p>
<figure class="highlight arduino"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs arduino">git config --global core.quotepath <span class="hljs-literal">false</span><br></code></pre></td></tr></table></figure>
            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/devops/">devops</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/git/">git</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2020/07/27/00%E7%AE%97%E6%B3%95%E4%B8%8E%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/02MD5%E7%AE%97%E6%B3%95%E5%8E%9F%E7%90%86/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">MD5算法原理</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2020/07/27/05%E5%88%86%E5%B8%83%E5%BC%8F%E5%8F%8A%E6%95%B0%E6%8D%AE%E5%BA%93/00%20%E4%BC%A0%E7%BB%9F%E6%95%B0%E6%8D%AE%E5%BA%93/00%20mysql/mysql%20%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/">
                        <span class="hidden-mobile">mysql 常用命令</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  

  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/js/local-search.js" ></script>



  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  






  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
        typing(title);
      
    })(window, document);
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
